﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Models;

namespace DAL
{
    /// <summary>
    /// 轮播
    /// </summary>
    public class RotationaDAL
    {
        //轮播添加
        public static int lunboAdd(Rotationa r) {
            string sql = "insert into tb_Rotationa(Title,image) values(@Title,@image)";
            SqlParameter[] para = { 
            new SqlParameter("@Title",r.Title),
            new SqlParameter("@image",r.image),
            };
            return SqlDBHelper.ExecuteNonQuery(sql,para);
        }
        //数据刷新
        public static DataTable selectLunbo()
        {
            string sql = "select * from tb_Rotationa";
            return SqlDBHelper.GetDataTable(sql);
        }
        //模糊查询
        public static DataTable mhCX(string title)
        {
            string sql = "select * from tb_Rotationa where Title like'%"+title+"%'";
            return SqlDBHelper.GetDataTable(sql);
        }
        //查询数据条数
        public static object dataNum()
        {
            string sql = "select count(*) from tb_Rotationa";
            return SqlDBHelper.ExecuteScalar(sql);
        }
        //图片查看
        public static object tupian(int id)
        {
            string sql = "select image from tb_Rotationa where RotationaID='" + id + "'";
            return SqlDBHelper.ExecuteScalar(sql);
        }
        //轮播删除
        public static int lbSC(int id) {
            string sql = "delete from tb_Rotationa where RotationaID=" + id;
            return SqlDBHelper.ExecuteNonQuery(sql);
        }
        //前台使用轮播
        //轮播
        //轮播图
        public static SqlDataReader SelectTbLunBo()
        {
            //控制只能显示前八类
            string sql = $"select * from tb_Rotationa";
            //调用连接查询
            return SqlDBHelper.GetReader(sql);
        }
    }
}
